<?php

namespace App\Models\Applet\Other;

class PaymentOrderModel extends BaseOtherModel
{
    protected $table = 'payment_order';

    const ORDER_TYPE_SPONSOR = 10; // 订单类型 认养类型
    const ORDER_TYPE_SHOP    = 20; // 订单类型 商城类型

    const PAY_TYPE_WECHAT = 10; // 微信支付
    const PAY_TYPE_ALIPAY = 20; // 支付宝支付

    const PAY_STATUS_WAIT    = 10; // 待支付
    const PAY_STATUS_SUCCESS = 20; // 已支付

    public static $orderType = [
        self::PAY_TYPE_WECHAT => '微信支付',
        self::PAY_TYPE_ALIPAY => '支付宝支付',
    ];

    /**
     * 根据主订单id获取数据
     * @param int $orderMasterId
     * @param array $fields
     * @return array
     */
    public function getItemByOrderId(int $orderMasterId, array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        $result = $this->select($fields)
                       ->where('order_id', $orderMasterId)
                       ->where('deleted', self::DELETED_NO)
                       ->first();
        return $result ? $result->toArray() : [];
    }

    /**
     * 根据主订单id获取数据
     * @param int $orderMasterId
     * @param array $fields
     * @return array
     */
    public function getItemByOrderIdAndStatusSuccess(int $orderMasterId, array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        $result = $this->select($fields)
                       ->where('order_id', $orderMasterId)
                       ->where('pay_status', self::PAY_STATUS_SUCCESS)
                       ->where('deleted', self::DELETED_NO)
                       ->first();
        return $result ? $result->toArray() : [];
    }
}
